﻿<template>
  <a-modal
    title="编辑凭证记录"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label=" 业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 业务分类，string类型，如门诊科室实际工作量报表（门诊收入凭证贷方）、套餐收入等9类" v-decorator="['classtype']" />
        </a-form-item>
        <a-form-item label=" 单据类型（入库场景=HSNC-01，出库场景=HSNC-10，其他的场景=HSNC-20） " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 单据类型（入库场景=HSNC-01，出库场景=HSNC-10，其他的场景=HSNC-20） " v-decorator="['pk_busitype']" />
        </a-form-item>
        <a-form-item label=" 接口请求唯一标识，用来确定数据唯一性字段" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 接口请求唯一标识，用来确定数据唯一性字段" v-decorator="['billid']" />
        </a-form-item>
        <a-form-item label=" NC公司编码（his直接带NC公司目录编码）" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 NC公司编码（his直接带NC公司目录编码）" v-decorator="['pk_corp']" />
        </a-form-item>
        <a-form-item label=" 日期" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择 日期" v-decorator="['billdate']" @change="onChangebilldate"/>
        </a-form-item>
        <a-form-item label=" 门诊住院项目编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 门诊住院项目编码" v-decorator="['projectcode']" />
        </a-form-item>
        <a-form-item label=" 门诊住院项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 门诊住院项目名称" v-decorator="['projectname']" />
        </a-form-item>
        <a-form-item label=" 科室部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 科室部门编码" v-decorator="['deptcode']" />
        </a-form-item>
        <a-form-item label=" 科室部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 科室部门名称" v-decorator="['deptname']" />
        </a-form-item>
        <a-form-item label=" 收款方式编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 收款方式编码" v-decorator="['intypecode']" />
        </a-form-item>
        <a-form-item label=" 收款方式名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 收款方式名称" v-decorator="['intypename']" />
        </a-form-item>
        <a-form-item label=" 仓库编码（根据实际药品采购入库仓库而定）" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 仓库编码（根据实际药品采购入库仓库而定）" v-decorator="['storecode']" />
        </a-form-item>
        <a-form-item label=" 仓库名称（根据实际药品采购入库仓库而定）" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 仓库名称（根据实际药品采购入库仓库而定）" v-decorator="['storename']" />
        </a-form-item>
        <a-form-item label=" 业务类型（his系统名称） " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 业务类型（his系统名称） " v-decorator="['histype']" />
        </a-form-item>
        <a-form-item label=" 供应商编码 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 供应商编码 " v-decorator="['suppliercode']" />
        </a-form-item>
        <a-form-item label=" 供应商名称 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 供应商名称 " v-decorator="['suppliername']" />
        </a-form-item>
        <a-form-item label=" 是否生成凭证" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 是否生成凭证" v-decorator="['istovoucher']" />
        </a-form-item>
        <a-form-item label=" 是否退货(Y,N默认N,负数传Y正数转N) " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 是否退货(Y,N默认N,负数传Y正数转N) " v-decorator="['backmoneyflag']" />
        </a-form-item>
        <a-form-item label=" 金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 金额" v-decorator="['money']" />
        </a-form-item>
        <a-form-item label=" 备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 备注" v-decorator="['memo']" />
        </a-form-item>
        <a-form-item label=" 自定义项1 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项1 " v-decorator="['def1']" />
        </a-form-item>
        <a-form-item label=" 自定义项2 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项2 " v-decorator="['def2']" />
        </a-form-item>
        <a-form-item label=" 自定义项3 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项3 " v-decorator="['def3']" />
        </a-form-item>
        <a-form-item label=" 自定义项4 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项4 " v-decorator="['def4']" />
        </a-form-item>
        <a-form-item label=" 自定义项5 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项5 " v-decorator="['def5']" />
        </a-form-item>
        <a-form-item label=" 自定义项6 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项6 " v-decorator="['def6']" />
        </a-form-item>
        <a-form-item label=" 自定义项7 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项7 " v-decorator="['def7']" />
        </a-form-item>
        <a-form-item label=" 自定义项8 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项8 " v-decorator="['def8']" />
        </a-form-item>
        <a-form-item label=" 自定义项9 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项9 " v-decorator="['def9']" />
        </a-form-item>
        <a-form-item label=" 自定义项10" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项10" v-decorator="['def10']" />
        </a-form-item>
        <a-form-item label=" 自定义项11" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项11" v-decorator="['def11']" />
        </a-form-item>
        <a-form-item label=" 自定义项12" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项12" v-decorator="['def12']" />
        </a-form-item>
        <a-form-item label=" 自定义项13" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项13" v-decorator="['def13']" />
        </a-form-item>
        <a-form-item label=" 自定义项14" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项14" v-decorator="['def14']" />
        </a-form-item>
        <a-form-item label=" 自定义项15" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项15" v-decorator="['def15']" />
        </a-form-item>
        <a-form-item label=" 自定义项16" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项16" v-decorator="['def16']" />
        </a-form-item>
        <a-form-item label=" 自定义项17" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项17" v-decorator="['def17']" />
        </a-form-item>
        <a-form-item label="自定义项18" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项18" v-decorator="['def18']" />
        </a-form-item>
        <a-form-item label="自定义项19" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项19" v-decorator="['def19']" />
        </a-form-item>
        <a-form-item label="自定义项20" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项20" v-decorator="['def20']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import {
    VoucherEdit
  } from '@/api/modular/main/VoucherManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        billdateDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              id: record.id,
              classtype: record.classtype,
              pk_busitype: record.pk_busitype,
              billid: record.billid,
              pk_corp: record.pk_corp,
              projectcode: record.projectcode,
              projectname: record.projectname,
              deptcode: record.deptcode,
              deptname: record.deptname,
              intypecode: record.intypecode,
              intypename: record.intypename,
              storecode: record.storecode,
              storename: record.storename,
              histype: record.histype,
              suppliercode: record.suppliercode,
              suppliername: record.suppliername,
              istovoucher: record.istovoucher,
              backmoneyflag: record.backmoneyflag,
              money: record.money,
              memo: record.memo,
              def1: record.def1,
              def2: record.def2,
              def3: record.def3,
              def4: record.def4,
              def5: record.def5,
              def6: record.def6,
              def7: record.def7,
              def8: record.def8,
              def9: record.def9,
              def10: record.def10,
              def11: record.def11,
              def12: record.def12,
              def13: record.def13,
              def14: record.def14,
              def15: record.def15,
              def16: record.def16,
              def17: record.def17,
              def18: record.def18,
              def19: record.def19,
              def20: record.def20
            }
          )
        }, 100)
        this.form.getFieldDecorator('billdate', { initialValue: moment(record.billdate, 'YYYY-MM-DD') })
        this.billdateDateString = moment(record.billdate).format('YYYY-MM-DD')
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.billdate = this.billdateDateString
            VoucherEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangebilldate(date, dateString) {
        this.billdateDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
